package com.microHR.hr.service.impl;

import com.microHR.hr.mapper.MailSendLogMapper;
import com.microHR.hr.model.MailSendLog;
import com.microHR.hr.model.MailSendLogExample;
import com.microHR.hr.service.MailSendLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
public class MailSendLogServiceImpl implements MailSendLogService {

    @Autowired
    private MailSendLogMapper mailSendLogMapper;

    public MailSendLogServiceImpl(MailSendLogMapper mailSendLogMapper) {
        this.mailSendLogMapper = mailSendLogMapper;
    }

    @Override
    public Integer updateMailSendLogStatus(String msgId, Integer status) {
        // 1. 构造 row 对象（仅设置 status 字段，其他为 null）
        MailSendLog row = new MailSendLog();
        row.setStatus(status);  // 仅设置 status，其他字段保持 null

        // 2. 构造 example 对象（设置 msgId 的条件）
        MailSendLogExample example = new MailSendLogExample();
        example.createCriteria()
                .andMsgidEqualTo(msgId);  // where msgId = #{msgId}

        // 3. 调用 MBG 的 updateByExampleSelective 方法
        return mailSendLogMapper.updateByExampleSelective(row, example);
    }

    @Override
    public Integer insert(MailSendLog mailSendLog) {
        return mailSendLogMapper.insert(mailSendLog);
    }

    @Override
    public List<MailSendLog> getMailSendLogsByStatus() {
        return Collections.emptyList();
    }

    @Override
    public Integer updateCount(String msgId, Date date) {
        return 0;
    }
}
